#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[200005];
struct lb{
	int num, nex, pre, fro, end;
	int ty;
}s[200005];
int cnt = 0;
int main(){
	freopen("fruit.in", "r", stdin);
	freopen("fruit.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	s[0].num = 0, s[0].ty = 0x3f3f3f3f, s[0].nex = 1;
	cnt = 1, s[1].num = 1, s[1].pre = 0, s[1].fro = 1, s[1].ty = a[1];
	for(int i = 2; i <= n; i++)
		if(a[i] != a[i - 1])
			cnt++, s[cnt].num = 1, s[cnt - 1].nex = cnt, s[cnt].pre = cnt - 1, s[cnt].nex = 0, s[cnt].fro = i, s[cnt].ty = a[i];
		else
			s[cnt].num++;
	s[cnt].nex = 0;
	int ans = cnt;
	while(ans > 0){
		int cur = s[0].nex;
		//printf("%d\n", ans);
		bool flag = false;
		if(s[s[cur].nex].ty == s[cur].ty)
				flag = true;
		while(true){
			if(s[cur].fro == 0)
				break;
			printf("%d ", s[cur].fro);
			s[cur].num--;
			s[cur].fro++;
			if(s[cur].num == 0)
				s[s[cur].pre].nex = s[cur].nex, s[s[cur].nex].pre = s[cur].pre, ans--;
			cur = s[cur].nex;
			if(cur == 0)
				break;
			if(s[s[cur].nex].ty == s[cur].ty){
				flag = true;
				continue;
			}
			if(flag)
				cur = s[cur].nex, flag = false;
		}
		printf("\n");
	}
	return 0;
}

